package genj;

import static org.junit.Assert.assertNotNull;
import genj.gedcom.Gedcom;
import genj.io.GedcomReader;
import genj.io.GedcomReaderFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Test;

import com.larsgard.gedviewer.server.ged.GenjGedParser;
import com.larsgard.gedviewer.server.storage.entities.JDOPerson;

public class ReadAGed {

    @Test
    public void readAfile() throws FileNotFoundException, IOException {
	File file = new File("test/gedcom.ged");
	System.out.println(file.getAbsolutePath());
	GedcomReader reader = GedcomReaderFactory.createReader(new FileInputStream(file), null);
	Gedcom gedcom = reader.read();
	assertNotNull(gedcom);
    }

    @Test
    public void parseAnIndiToPerson() throws FileNotFoundException, IOException {
	File file = new File("test/gedcom.ged");

	GenjGedParser parser = new GenjGedParser(new FileInputStream(file));
	while (parser.hasNext()) {
	    JDOPerson parsed = parser.next();
	    assertNotNull(parsed);
	}
    }

}
